/**
 * mailUtil类
 */
package com.bys.ots.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;


import com.alibaba.fastjson.JSONObject;
import net.sf.json.xml.XMLSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * 
 * @author bairuihua
 *  2019/11/26
 */
public class MailUtil
{
    Logger logger = LoggerFactory.getLogger(this.getClass());

    public String getRandomCode()
    {

        String model = "0123456789";
        char[] m = model.toCharArray();
        String randomcode = "";
        for (int j = 0; j < 4; j++)
        {
            char c = m[(int) (Math.random() * 10)];
            // 保证六位随机数之间没有重复的
            if (randomcode.contains(String.valueOf(c)))
            {
                j--;
                continue;
            }
            randomcode = randomcode + c;
        }
        return randomcode;
    }
public static void main (String[] args){
   String str="<response><code>0</code><message></message><shipment><nu>803590668</nu><shipmentid>803590668</shipmentid><com>Sunjex</com><status>1</status><status_V></status_V><state>3</state><state_V>送达签收</state_V><pod_url>http://tf-pod.vipservice.tech/202003/803590668.jpg?Expires=1583947571&OSSAccessKeyId=LTAI4Fg3HjPMd9TBvp4Qrdr6&Signature=IYlQfwIfhzCq2UVem0pYxHGVgMc%3D</pod_url><data><item><time>2020-03-03 23:00:00</time><location>1</location><context>提货已完成</context><status>35</status></item><item><time>2020-03-03 23:59:00</time><location>1</location><context>提货已完成</context><status>35</status></item><item><time>2020-03-04 07:29:00</time><location>1</location><context>提货已完成</context><status>35</status></item><item><time>2020-03-05 10:51:00</time><location>1</location><context>送达签收</context><status>75</status></item></data></shipment></response>";
    XMLSerializer xMLSerializer = new XMLSerializer();


        System.out.println(xMLSerializer.read(str));

}
//    public void sendAttachmentsMail(String to, String title, String cotent, List<File> fileList)
//    {
//
//        MimeMessage message = mailSender.createMimeMessage();
//
//        try
//        {
//            MimeMessageHelper helper = new MimeMessageHelper(message, true);
//            helper.setFrom(from);
//            helper.setTo(to);
//            helper.setSubject(title);
//            helper.setText(cotent);
//            String fileName = null;
//            for (File file : fileList)
//            {
//                fileName = MimeUtility.encodeText(file.getName(), "GB2312", "B");
//                helper.addAttachment(fileName, file);
//            }
//        }
//        catch (Exception e)
//        {
//            e.printStackTrace();
//        }
//        mailSender.send(message);
//        logger.info("邮件发送成功");
//    }

}
